import {
    reqCustomerName, //客户列表
    reqWebsiteList, //所属组织
    AdminBox, //所属销售
} from "@/api/customer";
import { carrierID } from "@/api/information";
const finance = {
    state: {
        checkType: '',//分为add,edit,info
        operateType: '',//分为add,edit,info
        checkDetailId: '',//对账单的id
        customerList: [],
        websiteList: [],
        adminList: [],
        carrierList: []
    },
    getters: {
        checkType: state => state.checkType,
        operateType: state => state.operateType,
        checkDetailId: state => state.checkDetailId,
        customerList: state => state.customerList,
        websiteList: state => state.websiteList,
        adminList: state => state.adminList,
        carrierList: state => state.carrierList

    },
    mutations: {
        CHANGE_CHECK_TYPE: (state, type) => {//对账调账
            state.checkType = type
        },
        CHANGE_OPERATE_TYPE: (state, type) => {//开票
            state.operateType = type
        },
        GET_CHECK_DETAIL_ID: (state, id) => {
            state.checkDetailId = id
        },
        GET_CUSTOMER_LIST: (state, list) => {
            state.customerList = list
        },
        GET_WEBSITE_LIST: (state, list) => {
            state.websiteList = list
        },
        GET_ADMIN_LIST: (state, list) => {
            state.adminList = list
        },
        GET_CARRIER_LIST: (state, list) => {
            state.carrierList = list
        },
    },
    actions: {
        changeCheckType({ commit, status }) {
            commit('CHANGE_CHECK_TYPE', status)
        },
        changeOperateType({ commit, status }) {
            commit('CHANGE_OPERATE_TYPE', status)
        },
        async getCustomerList({ commit }) {
            let result = await reqCustomerName({
                name: "",
                is_send: "1",
                is_receive: "",
            })
            commit('GET_CUSTOMER_LIST', result.data)
        },
        async getWebsiteList({ commit }) {
            let result = await reqWebsiteList({
                branch_type: "3"
            })
            commit('GET_WEBSITE_LIST', result.data)
        },
        async getAdminList({ commit }) {
            let result = await AdminBox({
                user_type: "0"
            })
            commit('GET_ADMIN_LIST', result.data)
        },
        async getCarrierList({ commit }) {
            let result = await carrierID({
                name: "",
            })
            commit('GET_CARRIER_LIST', result.data)
        }
    }
}

export default finance;
